
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<span style="font-size:18px;">
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="attendance/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="attendance/css/commonly-used-show.css" />
    <script type="text/javascript" src="attendance/js/jquery.min.js"></script>
    <script type="text/javascript" src="attendance/js/bootstrap.js" ></script>

    <title>课程信息管理</title>

    <style type="text/css">
        td, th {
            text-align: center;
        }
    </style>

</head>

<body class="mybody">


<jsp:include page="theTopMenuAdmin.jsp" />

<div class="container-fluid">
    <div class="row">



        <div class="col-md-12">
            <div class="col-md-12">
                    <div class="panel panel-primary">
                        <div class="panel-body">

                            <div>
    <h3 style="text-align: center">课程信息列表</h3>
    <table border="1" class="table table-bordered table-hover">
        <tr class="success">
            <th>序号</th>
            <th>课程编号</th>
            <th>课程名称</th>
            <th>任课老师</th>
            <th>创建时间</th>
            <th>操作</th>
        </tr>

        <c:forEach items="${allcourse}" var="course" varStatus="xh">
            <tr>
                <td>${xh.count}</td>
                <td>${course.id}</td>
                <td>${course.courseTitle}</td>
                <td>${course.instructor}</td>
                <td>${course.createTime}</td>
                <td><a class="btn btn-default btn-sm" href="${pageContext.request.contextPath}/updateCourse?id=${course.id}">修改</a>&nbsp;<a class="btn btn-default btn-sm" href="#" onclick="deletCourse('${course.id}')">删除</a></td>
            </tr>
        </c:forEach>

        <tr>
            <td colspan="6" align="center"><a class="btn btn-primary" href="${pageContext.request.contextPath}/addCourse">添加课程</a></td>
        </tr>

    </table>
</div>

                        </div>
                    </div>
                </div>
        </div>



    </div>

 </div>





<script type="text/javascript">
    var userdt = JSON.parse(sessionStorage.getItem("user"));
    if (userdt.result.userName != null){
        $("#usname").text(userdt.result.userName);
    }else {
        $("#usname").text(userdt.result.userLoginName);
    }


    function deletCourse(datees){
        var mymessage = confirm("你确定要删除该条信息吗？");
        if(mymessage === true) {
            deletCourse1(datees);
        }
    }

    function deletCourse1(id){
        var postUrl = "${pageContext.request.contextPath}/member/deletCourse";
        var str = {
            "id": id
        };

        $.ajax({
            type:"post",
            url:postUrl,
            headers: {
                "Content-Type":"application/json"
            },
            data:JSON.stringify(str),
            contentType: "application/json; charset=utf-8",
            dataType:"json",
            success:function(data){
                if (data.status == "0"){
                    alert(data.msg)
                }else {
                    location.reload();
                }
            },
            error:function(xhr,state,errorThrown){
                //alert("发生网络错误，错误码为：" + xhr.status)
                location.href = "${pageContext.request.contextPath}/error";
            }
        });
    }

</script>

</body>
</html>
</span>